package com.cwrl.spider.test.handle;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.crypto.digest.DigestUtil;
import org.eclipse.leshan.client.resource.BaseInstanceEnabler;
import org.eclipse.leshan.client.servers.LwM2mServer;
import org.eclipse.leshan.core.model.ObjectModel;
import org.eclipse.leshan.core.node.LwM2mResource;
import org.eclipse.leshan.core.request.argument.Arguments;
import org.eclipse.leshan.core.response.ExecuteResponse;
import org.eclipse.leshan.core.response.ReadResponse;
import org.eclipse.leshan.core.response.WriteResponse;

import java.util.List;

public class ConnectivityStatistics extends BaseInstanceEnabler {

    @Override
    public ReadResponse read(LwM2mServer identity, int resourceid) {
        switch (resourceid) {
            case 0:
                return ReadResponse.success(resourceid, Base64.encode("这个是测试数据0"));
            case 1:
                return ReadResponse.success(resourceid, Base64.encode("这个是测试数据1"));
        }
        return ReadResponse.notFound();
    }

    @Override
    public ReadResponse read(LwM2mServer identity, int resourceid, int resourceInstance) {
        return ReadResponse.notFound();
    }

    @Override
    public WriteResponse write(LwM2mServer identity, boolean replace, int resourceid, LwM2mResource value) {
        switch (resourceid) {
            case 15:
                System.out.println("收到" + resourceid + "的值:" + value.getValue());
                return WriteResponse.success();
        }
        return WriteResponse.notFound();
    }

    @Override
    public ExecuteResponse execute(LwM2mServer server, int resourceid, Arguments arguments) {
        switch (resourceid) {
            case 12:

                return ExecuteResponse.success();
        }
        return ExecuteResponse.notFound();
    }


    @Override
    public List<Integer> getAvailableResourceIds(ObjectModel model) {
        return CollUtil.newArrayList(0, 1, 2, 3);
    }
}
